package userInterface;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import org.quickconnect.QuickConnect;

import beans.SessionBean;

public class ChatSessionPanel extends JPanel {

	//Class Variables
	public static final int MESSENGER_PANEL_HEIGHT = 400;
	public static final int MESSENGER_PANEL_WIDTH = 300;
	public static final int FILE_PANEL_HEIGHT = 400;
	public static final int FILE_PANEL_WIDTH = 280;

	//Globals
	SessionBean session;
	MessengerPanel aMessengerPanel;
	FilePanel aFilePanel;
	ChatUserPanel aUserPanel;
	SessionPanelSwitcher switcher;
	JTabbedPane userAndFileTabs;
	//Constructors
	public ChatSessionPanel()  {
		Vector vector = new Vector();
		userAndFileTabs = new JTabbedPane(JTabbedPane.TOP);

		//Create panels
		JPanel container = new JPanel();
		aMessengerPanel = new MessengerPanel(MESSENGER_PANEL_WIDTH, MESSENGER_PANEL_HEIGHT);
		aFilePanel = new FilePanel(FILE_PANEL_WIDTH, FILE_PANEL_HEIGHT, vector);
		aFilePanel.setPreferredSize(new Dimension(FILE_PANEL_WIDTH + 10, FILE_PANEL_HEIGHT));
		aUserPanel = new ChatUserPanel();
		aUserPanel.setPreferredSize(new Dimension(FILE_PANEL_WIDTH + 10, FILE_PANEL_HEIGHT));
		switcher = new SessionPanelSwitcher();
		aMessengerPanel.setOpaque(true);
		aFilePanel.setOpaque(false);

		//Listeners for switching panel.
		SessionPanelSwitcher.theUserListPanel.addActionListener(new SwitchUserPanel());
		//SessionPanelSwitcher.theAgendaPanel.addActionListener(new SwitchAgendaPanel());
		//SessionPanelSwitcher.theMinutesPanel.addActionListener(new SwitchMinutesPanel());
		SessionPanelSwitcher.theFileReceivePanel.addActionListener(new SwitchFilePanel());
		userAndFileTabs.add("Active Users", aUserPanel);
		userAndFileTabs.add("Files", aFilePanel);

		container.add(aMessengerPanel);
		container.add(userAndFileTabs);
		//container.add(aFilePanel);
		//container.add(aUserPanel);
		//container.add(switcher);

		switcher.setOpaque(false);
		container.setOpaque(false);
		aUserPanel.setVisible(false);
		this.add(container);
		this.add(userAndFileTabs);


	}

	public class SwitchUserPanel implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {			
			aFilePanel.setVisible(false);
			aUserPanel.setVisible(true);
		}
	}

	public class SwitchAgendaPanel implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {			
			//TO Do
		}
	}

	public class SwitchMinutesPanel implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {			
			//TO Do
		}
	}

	public class SwitchFilePanel implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {			
			aFilePanel.setVisible(true);
			aUserPanel.setVisible(false);
		}
	}

	public ChatSessionPanel(SessionBean newSession) {
		this();
		this.session = newSession;
	}

	//Setters and Getters
	public SessionBean getSession() {
		return session;
	}

	public void setSession(SessionBean session) {
		this.session = session;
	}

	public MessengerPanel getaMessengerPanel() {
		return aMessengerPanel;
	}

	public void setaMessengerPanel(MessengerPanel aMessengerPanel) {
		this.aMessengerPanel = aMessengerPanel;
	}

	public FilePanel getaFilePanel() {
		return aFilePanel;
	}

	public void setaFilePanel(FilePanel aFilePanel) {
		this.aFilePanel = aFilePanel;
	}

	public ChatUserPanel getaUserPanel() {
		return aUserPanel;
	}

	public void setaUserPanel(ChatUserPanel aUserPanel) {
		this.aUserPanel = aUserPanel;
	}

}
